package cn.lsc.controller;

import cn.lsc.domain.User;
import cn.lsc.userbroke.UserBroke;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@RefreshScope // 动态刷新配置注解
public class UserController {

    @Value("${dynamicRefreshTest}")
    private String dynamicRefreshTest;

    @GetMapping("/findById/{id}")
    @SentinelResource(value = "user-service-findById",blockHandler = "degradationMethod",blockHandlerClass = UserBroke.class)
    public User findById(@PathVariable("id")Long id){
        return new User(id,"zs","hahaha"+dynamicRefreshTest);
    }

//    public User degradationMethod(@PathVariable("id")Long id, BlockException e){
//        e.printStackTrace();
//        return new User(-1L,"触发限流","别点了 你爹我遭不住了 cnmd！！！！");
//    }
}
